<template>
  <el-dialog title="种树" :visible.sync="dialogVisible" width="250px" @close="close">
    <el-form ref="onok" :model="form">
      <el-form-item prop="count" :rules="{ required: true, message: '不能为空', trigger: 'change' }">
        <el-input-number v-model="form.count" min="0" />
      </el-form-item>
    </el-form>
    <div style="text-align: center">
      <el-button
        :loading="loading"
        style="margin-top: 20px"
        type="primary"
        @click="onSubmit('onok')"
      >提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { handelRegister } from '../../../request/facilityList'
export default {
  props: ['containerIp', 'number'],
  data() {
    return {
      dialogVisible: false,
      loading: false,
      form: {
        count: undefined
      }
    }
  },
  methods: {
    close() {
      this.loading = false
    },
    async onSubmit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.loading = true
          this.handelRegister()
        }
      })
    },
    handelOpen() {
      this.dialogVisible = true
    },
    handelClose() {
      this.dialogVisible = false
    },
    async handelRegister() {
      const res = await handelRegister(this.containerIp, this.form.count)
      if (res) {
        this.handelClose()
        this.loading = false
      }
    }
  }
}
</script>
